<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="author" content="wangbo">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>对象</title>
</head>

<body>
  <script>
    // es5 字面量的方式
    let student = {
      name: "张三",
      age: 10,
      ['a' + 'b']: "测试",
      say: function () {
        console.log("生死契阔,与子成说,执子之手与子偕老")
      }
    }
    student.say()
    console.log(student.name)

    // 创建一个 Object 实例
    var person = new Object();
    person.name = "rose";
    person.age = 18;
    person.job = "actor";
    person.sayName = function () {
      console.log(this.name);
    };
    console.log(person);
    
    // 组合使用构造函数模式和原型模式
    function Person(name, age) {
      this.name = name;
      this.age = age;
    }
    Person.prototype.sayName = function () {
      console.log(this.name);
    };
    var p = new Person("rose", 18);
    console.log(p);



    let a = "name";
    console.log(student["name"])
    // []这种会将里边的 里边进行运算,可以取值
    console.log(student[a])
    console.log(student.ab)
    // 获取对象所有的属性
    for (let prop in student) {
      console.log(prop, student[prop])
    }




  </script>
</body>

</html>